package com.zyj.test.month1.day1;

import com.zyj.test.ListNode;

/**
 * @author Yijia Zhang
 * @create 2024-04-18 23:09
 */
public class code0002 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode dummy = new ListNode(-1);
        ListNode p = dummy;
        int t = 0;
        while (l1 != null || l2 != null || t > 0) {
            if (l1 != null) {
                t+= l1.val;
                l1 = l1.next;
            }
            if (l2 != null) {
                t += l2.val;
                l2 = l2.next;
            }

            p.next = new ListNode(t % 10);
            p = p.next;
            t /= 10;

        }
        return dummy.next;
    }


    public ListNode reverseNode(ListNode head) {
        ListNode dummy = null;
        ListNode p = head;
        while (p != null) {
            ListNode next = p.next;
            p.next = dummy;
            dummy = p;
            p = next;
        }
        return dummy;
    }
}
